package com.ants.boot.wx.controller;

import com.ants.boot.core.Response;
import com.ants.boot.wx.dto.wxbanner.QueryPageInfoDto;
import com.ants.boot.wx.service.WxBannerService;
import com.ants.boot.wx.vo.wxbanner.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * @author 蚂蚁会花呗
 * @date 2022/5/23 16:40
 */
@RestController
@RequestMapping("/wx/banner")
@Api(tags = "微信首页滚动图")
public class WxBannerController {

    @Autowired
    private WxBannerService wxBannerService;

    /**
     * 分页列表查询
     * @return
     */
    @PostMapping("page_info")
    @ApiOperation(value = "列表搜索查询",notes = "查询、搜索、分页")
    @ApiResponses({
            @ApiResponse(code = 200,message = "操作成功！",response = WxBannerVo.class)
    })
    public Response pageInfo(@RequestBody @Validated QueryPageInfoDto dto){
        return Response.okData(wxBannerService.pageInfo(dto));
    }

    /**
     * 新增
     * @param dto
     * @return
     */
    @PostMapping("add_banner")
    @ApiOperation(value = "新增",notes = "新增微信首页滚动图片")
    @ApiResponses({
            @ApiResponse(code = 200,message = "操作成功！")
    })
    public Response addBanner(@RequestBody @Validated AddWxBannerDto dto){
        boolean result = wxBannerService.addBanner(dto);
        if (!result){
            return Response.fail();
        }
        return Response.ok();
    }


    @PostMapping("update_banner")
    @ApiOperation(value = "更新",notes = "更新微信首页滚动图片")
    @ApiResponses({
            @ApiResponse(code = 200,message = "操作成功！")
    })
    public Response updateBanner(@RequestBody @Validated UpdateWxBannerDto dto){
        boolean result = wxBannerService.updateBanner(dto);
        if (!result){
            return Response.fail();
        }
        return Response.ok();
    }




    @PostMapping("del_banner")
    @ApiOperation(value = "删除",notes = "单个删除，或者多选删除")
    @ApiResponses({
            @ApiResponse(code = 200,message = "操作成功！")
    })
    public Response delBanner(@RequestBody @Validated DelWxBannerDto dto){
        boolean result = wxBannerService.delBanner(dto.getIds());
        if (!result){
            return Response.fail();
        }
        return Response.ok();
    }

    @PostMapping("change_status")
    @ApiOperation(value = "修改状态",notes = "更新状态")
    @ApiResponses({
            @ApiResponse(code = 200,message = "操作成功！")
    })
    public Response changeStatus(@RequestBody @Validated ChangeStatusDto dto){
        boolean result = wxBannerService.changeStatus(dto);
        if (!result){
            return Response.fail();
        }
        return Response.ok();
    }


    @GetMapping("list_banner")
    @ApiOperation(value = "小程序首页滚动图片",notes = "小程序首页滚动图片，最多3张，根据时间排序,返回字符串数组")
    @ApiResponses({
            @ApiResponse(code = 200,message = "操作成功！",response = String.class)
    })
    public Response listBanner(){
        return Response.okData(wxBannerService.listBanner());
    }


}
